<!DOCTYPE html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1,shrink-to-fit=no">
    <title>登录</title>
    <link rel="icon" href="/img/login.jpg" type="img/x-ico" />
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <link href="/css/signin.css" rel="stylesheet">
    <script src="/js/jquery.js"></script>
</head>
<body class="text-center">
<!--  用户登录form表单 -->
<form class="form-signin">
    <img class="mb-4" src="/img/login.jpg" width="72" height="72">
    <h1 class="h3 mb-3 font-weight-normal" >请登录</h1>
    <input type="text" class="form-control"
           placeholder="请输入邮箱地址" required="" autofocus="" id="email">
    <input type="password" class="form-control"
           placeholder="请输入密码" required="" id="password">
    <input  type="button" value="登录" class="btn btn-lg btn-primary btn-block" onclick="login()" />
<!--    <input  type="button" value="注册新账号" class="btn btn-lg btn-primary btn-block"  />-->

    <input  type="button" class="form-control" style="color: #00BB00;background: none;border: none;cursor: pointer;font-size: 22px;"
           value="注册新账号" required="" autofocus="" onclick="goRegistry()">
    <p class="mt-5 mb-3 text-muted">© <span text="${currentYear}">2019</span>-<span text="${currentYear}+1">2020</span></p>


</form>
</body>

<script>

    function login() {
        let email = $("#email").val();
        let password = $("#password").val();
        if(!email){
            alert("请输入邮箱");
            return;
        }
        if(!password){
            alert("请输入密码");
            return;
        }
        console.log('document.cookie >>>>>>>>>>>>',document.cookie);
        $.ajax({
            url:"http://www.test.com/api/user/login/" + email + "/" + password,
            type:"GET" ,
            crossDomain: true,
            // 下面这句话允许跨域的cookie访问
            xhrFields: {
                withCredentials: true
            },
            success:function (data,status,xhr) {
                console.log('*********** 登录返回 **********data:',data);
                console.log('document.cookie2222 >>>>>>>>>>>>',document.cookie);
                // alert(xhr.getResponseHeader("lagouSessionId"))
                if(data.code == 0){
                    console.log('登录验证成功，跳转到欢迎页 >>>>>>>>>>>>>');
                    window.location.href = "welcome.html"
                    // let skey = getCookie("lagouSessionId");
                }else{
                    alert(data.msg)
                }
            },
            error:function (err) {
                console.log(err);
                alert(err.responseText);
            }
        });
    };
    
    function goRegistry() {
         window.location.href = "register.html"
    }


    function getCookie(cookieName){
        var cookieValue="";
        console.log('>>>>>>>>>coo:',document.cookie)
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = cookies[i];
                if (cookie.substring(0, cookieName.length + 2).trim() == cookieName.trim() + "=") {
                    cookieValue = cookie.substring(cookieName.length + 2, cookie.length);
                    break;
                }
            }
        }
        return cookieValue;
    };

</script>


<style>
    .form-signin {
        width: 100%;
        max-width: 330px;
        padding: 15px;
        margin: 0 auto;
    }
    .form-signin .form-control {
        margin-top: 15px;
    }
</style>

</html>